//
//  YEvaluationViewController.m
//  何五路
//
//  Created by _ADY on 15/7/22.
//  Copyright (c) 2015年 _ADY. All rights reserved.
//

#import "YEvaluationViewController.h"

@interface YEvaluationViewController ()

@end

#define YEHight 100
@implementation YEvaluationViewController
@synthesize mTableView,aDic;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    
    mTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, screenMySize.size.width, screenMySize.size.height) style:UITableViewStyleGrouped];
    mTableView.delegate = self;
    mTableView.dataSource = self;
    mTableView.sectionHeaderHeight = 0.0;
    mTableView.sectionFooterHeight = 0.0;
    mTableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:mTableView];
    
    UIView *v = [[UIView alloc] initWithFrame:CGRectZero];//清除多余分割线
    [mTableView setTableFooterView:v];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.view.backgroundColor =bgColor;
    self.title = @"评价晒单";
}

#pragma mark -
#pragma mark Table View DataSource

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
        return 0.001;
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1) {
        return 1;
    }
    return [[aDic objectForKey:@"OrderItems"] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        return YEHight/2;
    }
    return YEHight;
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"YECell";
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        aTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        aTableView.showsVerticalScrollIndicator = NO;
    }
    int i = (int)[[cell.contentView subviews] count] - 1;
    for(;i >= 0 ; i--)
    {
        [[[cell.contentView subviews] objectAtIndex:i] removeFromSuperview];
    }
    cell.backgroundColor = [UIColor whiteColor];

    if (indexPath.section == 0)
    {
        NSMutableArray *marray = [aDic objectForKey:@"OrderItems"];
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,10, YEHight-20,YEHight-20)];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[marray objectAtIndex:indexPath.row] objectForKey:@"ProdcutPictureUrl"]]]];
        bgImageView.contentMode =  UIViewContentModeScaleAspectFit;
        [cell.contentView addSubview:bgImageView];
        
        UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(9.5,9.5, YEHight-19,YEHight-19)];
        [bg1ImageView setImage:[UIImage imageNamed:@"gwckk"]];
        [cell.contentView addSubview:bg1ImageView];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(YEHight, 10, screenMySize.size.width-YEHight-20, YEHight-40) setTitle:[NSString stringWithFormat:@"%@",[[marray objectAtIndex:indexPath.row] objectForKey:@"ProductName"]] setFont:labelSize setColor:[UIColor blackColor]]];
        
        //未评价 1  已评价 2
        UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
        if ([[NSString stringWithFormat:@"%@",[aDic objectForKey:@"ReviewsStatus"]] isEqualToString:@"1"])
        {
            [button1 setBackgroundImage:[UIImage imageNamed:@"Epjsd"] forState:UIControlStateNormal];
        }
        else if ([[NSString stringWithFormat:@"%@",[aDic objectForKey:@"ReviewsStatus"]] isEqualToString:@"2"])
        {
            [button1 setBackgroundImage:[UIImage imageNamed:@"Ezjst"] forState:UIControlStateNormal];
        }
        [button1 setFrame:CGRectMake(screenMySize.size.width-10-139/2, YEHight-10-49/2, 139/2, 49/2)];
        button1.tag = 100+indexPath.row;
        [button1 addTarget:self action:@selector(setButtonTag:) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:button1];
        
    }
    else
    {
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, 10, screenMySize.size.width-100, YEHight/2-20) setTitle:@"服务评价" setFont:labelSize+2 setColor:[UIColor blackColor]]];
        
        UIButton *xButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [xButton setFrame:CGRectMake(screenMySize.size.width-90, (YEHight/2-30)/2, 80, 30)];
        [xButton setBackgroundImage:[UIImage imageNamed:@"enButton"] forState:UIControlStateNormal];
        [xButton setTitle:@"已完成" forState:UIControlStateNormal];
        [xButton setTitleColor:[UIColor colorWithRed:205/255.0 green:205/255.0 blue:205/255.0 alpha:1] forState:UIControlStateNormal];
        xButton.enabled = NO;
        
        [xButton addTarget:self action:@selector(xAction) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:xButton];
    }
    return cell;
}

-(void)setButtonTag:(id)sender
{
    int type = ((UIButton*)sender).tag-100;
    WEvaluationViewController *details = [[WEvaluationViewController alloc] init];
    details.hidesBottomBarWhenPushed = YES;
    details.IntPex = type;
    details.aDic = aDic;
    [self.navigationController pushViewController:details animated:YES];
}

-(void)xAction
{
    
}

-(UILabel*)setFrame:(CGRect)frame setTitle:(NSString*)title setFont:(int)font setColor:(UIColor*)myColor
{
    title = [title stringByReplacingOccurrencesOfString:@"<null>" withString:@""];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame];
    if (title != nil)
        titleLabel.text = [NSString stringWithFormat:@"%@",title];
    titleLabel.textAlignment = 0;
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont fontWithName:@"Arial" size:font];
    titleLabel.textColor = myColor;
    return titleLabel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
